package com.itheima.service.impl;
/*
    ヾ(❀ﾟ▽ﾟ)ノ 
 
 Grey1996year@163.com 
 
*/

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.mapper.MemberMapper;
import com.itheima.pojo.Member;
import com.itheima.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.*;


@Service(interfaceClass = MemberService.class)
public class MemberServiceImpl implements MemberService {

	@Autowired
	private MemberMapper memberMapper;


	@Override
	public Member queryIsMember(String telephone) {

		Member member = memberMapper.queryIsMember(telephone);

		return member;
	}

	@Override
	public void addMember(Member member) {
		memberMapper.addMember(member);
	}

	@Override
	public Map queryMonthAndMemberCount() {
		//1.查出来会员表  所有的注册日期
		List<String> months = memberMapper.queryMonths();
		System.out.println(months);

		HashMap<String, List> hashMap = new HashMap<>();

		List<String> list_date = new ArrayList();
		List<Integer> list_memberCount = new ArrayList();

		//定义会员的总数
		int memberCount = 0;

		for (String date : months) {
			//切割字符串
			String[] strings = date.split("-");
			String year = strings[0];
			String month = strings[1];

			String begin = year + "-" + month + "-1";
			String end = year + "-" + month + "-31";
			HashMap<String, String> map = new HashMap<>();
			map.put("begin", begin);
			map.put("end", end);
			//拼接满足格式的日期
			String dat = year + "." + month;
			//添加进集合
			list_date.add(dat);
			//查询会员数
			memberCount += memberMapper.queryMemberCount(map);
			//添加进集合
			list_memberCount.add(memberCount);

		}
		//循环遍历完成后，会把所有查询的结果添加进list集合，再将list集合封装到map集合中
		//添加进map
		hashMap.put("months", list_date);
		hashMap.put("memberCount", list_memberCount);

		return hashMap;
	}

}
